package com.blacktry.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blacktry.entity.blog.Comments;
import com.blacktry.mapper.blog.CommentsMapper;
import com.blacktry.service.CommentsService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author blackTry
 * @since 2022-02-07
 */
@Service
public class CommentsServiceImpl extends ServiceImpl<CommentsMapper, Comments> implements CommentsService {

    @Override
    public Map<Integer, List<Integer>> selectCommentsByArticleId(Integer articleId) {
        List<Integer> key = new ArrayList<>();
        key = this.baseMapper.selectCommentsByArticleId(articleId);
        Map<Integer, List<Integer>> map = new HashMap<>();
        for (int i = 0; i < key.size(); i++) {
            Integer parent = key.get(i);
            if (parent != null ) {
                List<Integer> list = this.baseMapper.selectCommentsByParentCommentId(parent, articleId);
                map.put(parent, list);
            }

        }
        return map;
    }

    @Override
    public Integer insertCommentsByArticleId(Integer articleId, String userId) {
        return this.baseMapper.insertCommentsByArticleId(articleId,userId);
    }

    @Override
    public Integer deleteCommentsByCommentId(Integer commentId) {
        return this.baseMapper.deleteCommentsByCommentId(commentId);
    }
}
